// pages/zwyy/zwyy.js
const db = wx.cloud.database()
var times = require('../../utils/times.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        Seat_Reservation: [],
        Appointment_info: '',
        active: '',
        user:''
    },

    stdy(e) {
        this.setData({ active: 1 })
    },
    login_register(e) {
        this.setData({ active: e.detail.index })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getSeatList()
        this.getlist()
    },
    //获取座位信息
    getSeatList() {
        db.collection("Seat_Reservation").get({
            success: res => {
                this.setData({
                    Seat_Reservation: res.data
                })
            }
        })
    },
    //时间选择
    timechoose: function (e) {
        let user = wx.getStorageSync('user')
        if (!user == '') {
            wx.navigateTo({
                url: '../timechoose/timechoose?time_id=' + e.currentTarget.id,
            })
        } else {
            wx.showToast({
                title: '请先登录！',
                icon: 'none'
            })
        }
        console.log(e.currentTarget.id)
    },
    //获取预约信息
    getlist() {
        let phone = wx.getStorageSync('user')
        console.log(phone, '1111')
        db.collection("userInfo").where({ phone: phone._id }).get().then(res => {
            for (var i = 0; i < res.data.length; i++) {
                res.data[i]["_createTime"] = times.toDate(res.data[i]["_createTime"])
                res.data[i]["check_time"] = times.toDate(res.data[i]["check_time"])
                res.data[i]["_updateTime"] = times.toDate(res.data[i]["_updateTime"])
                res.data[i]["qxTime"] = times.toDate(res.data[i]["qxTime"])
            }
            this.setData({
                Appointment_info: res.data,
            })
        })
    },

    Agin_appointment(e) {
        wx.navigateTo({
            url: '../timechoose/timechoose?time_id=' + e.currentTarget.id,
        })
    },





    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let user = wx.getStorageSync('user')
        console.log('缓存的user', user)
        this.setData({
            user: user,
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },
    clickfenlei(e) {
        var index = e.currentTarget.dataset.index;
        if (index != this.data.currentIndex) {
            this.setData({
                currentIndex: index
            })
        }
    },
    clickfenlei1(e) {
        var index = e.currentTarget.dataset.index;
        if (index != this.data.currentIndex1) {
            this.setData({
                currentIndex1: index
            })
        }
    },
    clickfenlei2(e) {
        var index = e.currentTarget.dataset.index;
        if (index != this.data.currentIndex2) {
            this.setData({
                currentIndex2: index
            })
        }
    }
})